<%@ page contentType="text/html;charset=UTF-8" %>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>T_building_house信息维护</title>
    <%@ include file="../../common/meta.jsp" %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen" id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top: 1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<form class="form-horizontal form-bordered form-row-strippe" name="ffAdd" id="ffAdd" mentod="post" role="form"
      data-toggle="validator" enctype="multipart/form-data">
    <div class="" style="margin-right:2px;padding-right:1px;">

        <!-------------------------- 面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-heading clearfix" id="addHeaderDiv">
            </div>
            <div class="panel-body">
                <div class="row">
                    <h5>&nbsp;&nbsp;基本信息</h5>
                    <hr>
                    <div class="col-xs-6"><!--start 换列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>楼栋名称</label>
                                <div class="col-xs-9">
                                    <select id="buildingname" name="buildingname" class="form-control">
                                    </select>
                                    <input id="buildingid" name="buildingid" type="hidden"/>
                                    <input id="buildingtype" name="buildingtype" type="hidden" value="1"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>房源名称</label>
                                <div class="col-xs-9">
                                    <input id="housename" name="housename" type="text" class="form-control"
                                           placeholder=""/>
                                    <input id="houseid" name="houseid" type="hidden"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>装修</label>
                                <div class="col-xs-9">
                                    <select id="fix" name="fix" class="form-control">
                                        <option value="简装">简装</option>
                                        <option value="毛坯">毛坯</option>
                                        <option value="精装">精装</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>租赁单价(元/平方米)</label>
                                <div class="col-xs-9">
                                    <input id="zuilinbaseprice" name="zuilinbaseprice" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>

                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>房源初始时间</label>
                                <div class="col-xs-9">
                                    <input id="ext1" name="ext1" type="text" class="form-control"
                                           placeholder="请选择日期" onclick='SelectDate(this)' readonly='true'/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>状态</label>
                                <div class="col-xs-9">
                                    <select id="status" name="status" class="form-control">
                                        <option value="空置">空置</option>
                                        <option value="已销售">已销售</option>
                                        <option value="已租赁">已租赁</option>
                                        <option value="自用">自用</option>
                                        <option value="已锁定">已锁定</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>附件上传</label>
                                <div class="col-xs-9">
                                    <a href="#"
                                       onclick="javascript:window.open('<%=basePath%>upload/toUploadOneFile2?oldfilename=ext4&newfilename=imagepath&filegroup=1099','','status=yes,scrollbars=yes,location=no,top=300,left=500,width=420,height=300')">上传附件</a>
                                    <input id="imagepath" name="imagepath" type="hidden" value="" class="form-control"/>
                                    <input id="ext4" name="ext4" type="hidden" value="" class="form-control"/>

                                </div>
                            </div>
                        </div>

                        <!--如果输入元素是偶数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int时输出2列格式；需要换列，每行最多显示2列-->
                    </div><!--end 换列--><!--start 换列-->
                    <div class="col-xs-6">
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>楼层</label>
                                <div class="col-xs-9">
                                    <input id="floornum" name="floornum" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>面积（平方米）</label>
                                <div class="col-xs-9">
                                    <input id="area" name="area" type="text" class="form-control" placeholder=""/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>标签</label>
                                <div class="col-xs-9">
                                    <select id="ext2" name="ext2" class="form-control"/>
                                    <option value="办公">办公</option>
                                    <option value="商住">商住</option>
                                    <option value="厂房">厂房</option>
                                    <option value="商业">商业</option>
                                    <option value="其它">其它</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>销售单价</label>
                                <div class="col-xs-9">
                                    <input id="salebaseprice" name="salebaseprice" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><font color="red">*</font>层高（米）</label>
                                <div class="col-xs-9">
                                    <input id="hight" name="hight" type="text" class="form-control"
                                           placeholder=""/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> <font color="red">*</font>上架状态</label>
                                <div class="col-xs-9">
                                    <select id="showstatus" name="showstatus" class="form-control">
                                        <option value="未上架">未上架</option>
                                        <option value="已上架">已上架</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"><strong>附件列表</strong></label>
                                <div class="col-xs-9">
                                    <table border="0" id="filetableDiv">
                                        <thead id="grid_head">
                                        <tr>
                                            <td></td>
                                        </tr>
                                        <tbody id="fileListDiv"></tbody>
                                    </table>
                                </div>
                            </div>
                        </div>

                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->

            <div class="modal-footer bg-info " id='buttonDiv'>
            </div>
        </div>
        <!--------------------------面板 end------------------------------------>

        <!-- 模态框（Modal）start -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">提示</h4>
                    </div>
                    <div class="modal-body" id="myModalMessDiv"></div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
        <!-- 模态框（Modal）end -->
    </div>
</form>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js"></script>
<script src="<%= basePath %>js/calendar.js"></script>
<script type="text/javascript">
    //新增保存数据
    function add() {
        $("#addSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_building_house/saveT_building_house?time=" + Math.random();
        var postData = $("#ffAdd").serializeArray();
        //alert(postData);
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(data);
            if (data.result == "success") {
                //保存成功  1.关闭弹出层，
                showSuccessTips("恭喜保存成功!", "提示");
            } else {
                $("#addSaveButton").removeAttr("disabled");
                //showErrorTips("保存数据失败!", "错误信息：");
                $("#myModal").modal('show'); //hide;
                $("#myModalMessDiv").html("<font color='red'>对不起,保存数据失败，失败原因：" + data.info + "</font>");
                return false;
            }
        }).error(function () {
            $("#addSaveButton").removeAttr("disabled");
            //showErrorTips("保存数据失败!", "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起,保存数据失败，失败原因：" + data.info + "</font>");
        });
    }

    //更新修改数据到后台
    function edit() {
        $("#editSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_building_house/updateT_building_house?time=" + Math.random();
        myEdit2(url);
    }

    //更新修改数据到后台并且启动工作流
    function tjsh() {
        $("#editSaveButton").attr("disabled", true);
        $("#tjshSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_building_house/tjshT_building_house?time=" + Math.random();
        myCurdTjsh(url);
    }

    //展示附件文件列表；
    function showFileList(oldfilenames, newfilenames){
        var showmess= oldfilenames.split(";");
        var newfilename= newfilenames.split(";");
        var trtdlist = "";
        for (var i = 0; i < showmess.length; i++ ){
            trtdlist += "<tr><td><a href='<%=basePath%>download?filename="+newfilename[i]+"'>"+showmess[i]+"</a></td></tr>";
        }
        $("#fileListDiv").html("");
        document.getElementById("fileListDiv").innerHTML = trtdlist;
    }
    //删除附件
    function deleteAllFile(id) {
        var url = "<%=basePath%>t_building_house/delT__building_houseAllFile?id=" + id +"&time="+Math.random();
        bootbox.confirm({
            size: 'small',
            buttons: {
                confirm: {
                    label: ' 删除 ',
                    className: 'btn btn-sm btn-danger'
                },
                cancel: {
                    label: '   取消     ',
                    className: 'btn btn-success btn-sm'
                }
            },
            message: '您确认要删除全部附件？删除后根据需要重新上传！',
            callback: function(result) {
                if(result) {if(result){ myBuildingHouseAllFileDel(url);}}
            },
            title:'删除附件提示：',
            className:' '
        })
    }

    //删除楼栋附件
    function myBuildingHouseAllFileDel(url) {
        $.get(url, function (data) {
            if ("success" == data.result) {
                showSuccessTips("删除成功", "提示");
                $("#fileListDiv").html("");
                $("#imagepath").val("");
                //$("#attach").val("");
                $("#ext4").val("");
            } else {
                showErrorTips("删除数据" + id + "失败!", "错误信息：");
            }
        });
    }

    //获取楼栋列表信息
    function getBuildingList() {
        var url = "<%=basePath%>t_building/getAllT_building?buildingtype=1&startIndex=0&pageSize=10000&time=" + Math.random();
        $.ajaxSettings.async = false;    //在执行之前加(同步执行)
        $.getJSON(url, function (data) {
            var str = "";
            $.each(data.items, function (i, item) {
                str += "<option value='" + item.name + "'>" + item.name + "</option>";
            });//end each data;
            $("#buildingname").append(str);
            //alert("str="+str);
        });//end getJSON;
    }

    //初始化页面及校验
    $().ready(function () {
        //1、初始化数据显示
        var name = "房源";
        var optype = '<%=request.getParameter("oplx")%>';
        var id = '<%=request.getParameter("id")%>';
        //alert("optype="+optype+";id="+id);
        if (optype == 'add') {
            $("#ffAdd")[0].reset();/*重置表单*/
            var basePath = "<i class='icon-plus'></i>&nbsp;";
            setHeader2("新增" + name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivAdd2();//设置adddiv的 操作按钮
            getBuildingList();
        } else if (optype == 'edit') {
            var basePath = "<i class='icon-pencil'></i>&nbsp;";
            setHeader2("修改" + name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivEdit2();//设置adddiv的 操作按钮
            //setButtonDivEdit4();//设置adddiv的 操作按钮
            getBuildingList();
            var url = "<%=basePath%>t_building_house/getT_building_house?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                if(null!=data.ext4 &&""!=data.ext4){
                    showFileList(data.ext4, data.imagepath); //设置附件列表展示；
                    var trtdlist ="<a href='javascript:deleteAllFile(<%=request.getParameter("id")%>)' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span>删除全部附件</a>&nbsp;&nbsp;";
                    $("#fileListDiv").append(trtdlist);
                }
            });
        } else if (optype == 'view') {
            var basePath = "<i class='icon-eye-open'></i>&nbsp;";//设置addHeaderDiv标题文字及按钮
            setHeader2("查看" + name, basePath);
            setButtonDivView2();//设置adddiv的 操作按钮
            getBuildingList();
            var url = "<%=basePath%>t_building_house/getT_building_house?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                if(null!=data.ext4 &&""!=data.ext4){
                    showFileList(data.ext4, data.imagepath); //设置附件列表展示；
                }
            });
            formReadOnly('ffAdd');//设置表单不可修改
        }

        //2、校验脚本初始化，start check
        $("#ffAdd").validate({
            submitHandler: function (form) {
                //alert($("#opType").val());
                if ($("#opType").val() == "add") {
                    add();
                } else if ($("#opType").val() == "edit") {
                    edit();
                }
            },
            rules: {
                houseid: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                housename: {
                    required: true,
                    maxlength: 256
                },
                buildingid: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                ext1: {
                    required: true,
                    maxlength: 45
                },
                floornum: {
                    required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                buildingname: {
                    required: true,
                    maxlength: 256
                },
                buildingtype: {
                    //required: true,
                    maxlength: 45
                },
                status: {
                    //required: true,
                    maxlength: 45
                },
                customername: {
                    //required: true,
                    maxlength: 45
                },
                customerid: {
                    //required: true,
                    maxlength: 45
                },
                compactstarttime: {
                    //required: true,
                    maxlength: 45
                },
                compactendtime: {
                    //required: true,
                    maxlength: 45
                },
                compactsigntime: {
                    //required: true,
                    maxlength: 45
                },
                zuilinbaseprice: {
                    required: true,
                    number: true,
                    //minlength: 1,
                    maxlength: 22
                },
                area: {
                    required: true,
                    number: true,
                    //minlength: 1,
                    maxlength: 22
                },
                fix: {
                    required: true,
                    maxlength: 45
                },
                salebaseprice: {
                    required: true,
                    number: true,
                    //minlength: 1,
                    maxlength: 22
                },
                applystarttime: {
                    //required: true,
                    maxlength: 45
                },
                applyendtime: {
                    //required: true,
                    maxlength: 45
                },
                vr: {
                    //required: true,
                    maxlength: 1024
                },
                imagepath: {
                    required: true,
                    maxlength: 1024
                },
                hight: {
                    required: true,
                    maxlength: 12
                },
                emptydays: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                showstatus: {
                    //required: true,
                    maxlength: 45
                },
                ext2: {
                    //required: true,
                    maxlength: 45
                },
                ext3: {
                    //required: true,
                    maxlength: 45
                },
                ext4: {
                    //required: true,
                    maxlength: 45
                },
                ext5: {
                    //required: true,
                    maxlength: 45
                },
                ext6: {
                    //required: true,
                    maxlength: 45
                },
                biztype: {
                    //required: true,
                    maxlength: 45
                }
            }, //end rules;
            messages: {
                houseid: {
                    //required: "房源id不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>房源id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                housename: {
                    required: "<font color='red'>房源名称不能为空！</font>！",
                    maxlength: "<font color='red'>房源名称最大支持256位,输入的数据已经超过最大长度！</font>"
                },
                buildingid: {
                    //required: "楼栋id不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>楼栋id最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                ext1: {
                    required: "<font color='red'> 房源初始时间不能为空！</font>！",
                    maxlength: "<font color='red'> 房源初始时间最大支持22位,输入的数据已经超过最大长度！</font>"
                },
                floornum: {
                    required: "<font color='red'>楼层不能为空！</font>",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>楼层最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                buildingname: {
                    required: "<font color='red'>楼栋名称不能为空！</font>",
                    maxlength: "<font color='red'>楼栋名称最大支持256位,输入的数据已经超过最大长度！</font>"
                },
                buildingtype: {
                    maxlength: "<font color='red'> buildingtype最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                status: {
                    maxlength: "<font color='red'> status最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                customername: {
                    maxlength: "<font color='red'> customername最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                customerid: {
                    maxlength: "<font color='red'> customerid最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                compactstarttime: {
                    maxlength: "<font color='red'> compactstarttime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                compactendtime: {
                    maxlength: "<font color='red'> compactendtime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                compactsigntime: {
                    maxlength: "<font color='red'> compactsigntime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                zuilinbaseprice: {
                    required: "<font color='red'>租赁单价不能为空！</font>",
                    number: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> 租赁单价最大支持12位,输入的数据已经超过最大长度！</font>"
                },
                area: {
                    required: "<font color='red'>面积不能为空！</font>",
                    number: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>面积最大支持12位,输入的数据已经超过最大长度！</font>"
                },
                fix: {
                    required: "<font color='red'>装修不能为空！</font>",
                    maxlength: "<font color='red'>装修最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                salebaseprice: {
                    required: "<font color='red'>销售单价不能为空！</font>",
                    number: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> 销售单价最大支持12位,输入的数据已经超过最大长度！</font>"
                },
                applystarttime: {
                    maxlength: "<font color='red'>开始时间最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                applyendtime: {
                    maxlength: "<font color='red'> applyendtime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                vr: {
                    maxlength: "<font color='red'>vr地址最大支持1,024位,输入的数据已经超过最大长度！</font>"
                },
                imagepath: {
                    required: "<font color='red'> 图片不能为空！</font>！",
                    maxlength: "<font color='red'>房源图片最大支持1,024位,输入的数据已经超过最大长度！</font>"
                },
                hight: {
                    required: "<font color='red'> 层高不能为空！</font>！",
                    maxlength: "<font color='red'>层高最大支持12位,输入的数据已经超过最大长度！</font>"
                },
                emptydays: {
                    //required: "空置天数不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>空置天数最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                showstatus: {
                    maxlength: "<font color='red'> showstatus最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext2: {
                    maxlength: "<font color='red'> ext2最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext3: {
                    maxlength: "<font color='red'> ext3最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext4: {
                    maxlength: "<font color='red'> ext4最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext5: {
                    maxlength: "<font color='red'> ext5最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                ext6: {
                    maxlength: "<font color='red'> ext6最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                biztype: {
                    maxlength: "<font color='red'> biztype最大支持45位,输入的数据已经超过最大长度！</font>"
                }
            } //end message;
        }); //end validate;
    }) //end funciton read;
</script>
